/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.universityUnits;

import model.Constants;
import model.entitys.Entity;

/**
 * Class represents curriculum of academic group. Curriculum is set of academic
 * disciplines. It has owner - group.
 * @author Dmitri Paziy
 */
public class Curriculum extends Entity<Lesson> implements CurriculumInterface {

    private final GroupInterface group;

    public Curriculum(GroupInterface group) {
        this.group = group;
    }

    /**
     * Getter of group - curriculum owner.
     * @return Restricted group
     */
    @Override
    public GroupInterface getGroup() {
        return group;
    }

    /**
     * Getter of discipline by its name. If such discipline wasn't found, 
     * <i>null</i> value is returned. 
     * @param name Name of discipline
     * @return Lesson or null.
     */
    @Override
    public Lesson getLesson(String name) {
        for (int index = 0; index < size(); index++) {
            Lesson lesson = get(index);
            
            if (lesson.getName().equals(name)) {
                return lesson;
            }
        }
        
        return null;
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();

        builder.append("Curruculum of ");
        builder.append(group.getName());
        builder.append(":");
        builder.append(Constants.LINE_SEPARATOR);

        for (int index = 0; index < size(); index++) {
            builder.append(get(index).toString());
        }

        return builder.toString();
    }
}
